Refactor (packages/web/src/components/share/part.tsx): Function with high complexity: flattenToolArgs - #63
Open
mmirzata wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #62
Type of change
What does this PR do?
Qlty flagged
flattenToolArgsinpart.tsxfor high complexity (count = 21). The arraybranch repeated the same object-vs-leaf check the function already did at the top, adding
duplication and nesting.
I moved the function into a new
part-utils.tsand exported it so it can be tested, andrewrote it so objects and arrays share one path (arrays just format the key as
[i]instead of
.key). Output is unchanged, so same[path, value]pairs.I used Claude to help with the refactor and the tests, following the instruction alone was not enough.
How did you verify your code works?
Added
part-utils.test.tswith 5 tests covering nested objects/arrays, primitives andnull, non-object input, empty inputs, and array bracket paths. All 5 pass with 100%
coverage on
part-utils.ts, andqlty smellsno longer reports the smell.Screenshots / recordings
Before: Qlty smell (count = 21):

After: no smell on

part-utils.ts:Tests passing, 100% coverage:

Lint: filtering bun lint to my changed files returns nothing, confirming part-utils.ts and part.tsx have no lint errors (the repo's only lint errors are pre-existing, in unrelated files I didn't modify).

Checklist